package com.example.algorithm.tree;

/**
 * @author : zhy
 * @since : 2022/7/30
 * 二叉树最大深度
 */
public class TreeMaxDeep {

    public int maxDepth(TreeNode root) {
        return dfs(root);
    }

    private int dfs(TreeNode root) {

        if(root==null)
        {
            return 0;
        }
        int left=dfs(root.left);
        int right=dfs(root.right);
        return left>right?left+1:right+1;
    }
}
